import { buildColumns } from '@/utils/table'
import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import type { FilterItem } from '@/components/strong-search'
export default function useTableColumn() {
  const columns = computed(() =>
    buildColumns([
      {
        title: '用户账号',
        width: 236,
        dataIndex: 'username'
      },
      {
        title: '邮箱',
        width: 236,
        dataIndex: 'email'
      },
      {
        title: '备注',
        width: 236,
        dataIndex: 'remark',
        slotName: 'remark'
      },
      {
        title: '状态',
        width: 120,
        dataIndex: 'status',
        slotName: 'status'
      },
      {
        title: '添加时间',
        width: 190,
        dataIndex: 'created_at',
        format: 'date-time',
        sortable: sortableSettings
      },
      {
        title: '操作',
        width: 150,
        slotName: 'action',
        fixed: 'right',
        cellClass: 'actions-cell'
      }
    ])
  )
  const filterSchemes = computed<CloudFilterBarScheme>(() => {
    const strongSearchOptions: FilterItem[] = [
      {
        label: '用户账号',
        field: 'username_keyword'
      },
      {
        label: '添加时间',
        popover: 'date',
        popoverOption: {
          dateProps: {
            startKey: 'created_at_begin',
            endKey: 'created_at_end'
          }
        },
        field: 'created_at'
      }
    ]
    return {
      widgets: [
        {
          widget: 'strong-search',
          placeholder: '默认按照用户账号搜索',
          options: strongSearchOptions
        }
      ]
    }
  })
  return { columns, filterSchemes }
}
